//
//  DYESPAuthVC.m
//  TerritoryShopkeeper
//
//  Created by 黄德玉 on 2018/7/12.
//  Copyright © 2018年 ZDQK. All rights reserved.
//

#import "DYESPAuthVC.h"
#import "DYESPAuthView.h"
#import "GoodsListFiltrateViewController.h"
#import "OpenShopIntroVC.h"


@interface DYESPAuthVC ()

@property (nonatomic, strong) DYESPAuthView * authView;
@end

@implementation DYESPAuthVC

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.authType = 1;
    }
    return self;
}

- (void)loadView{
    self.view = self.authView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self _setupNav];
//    [UserInfo shareInstance].user
}

- (void)_setupNav{
    self.title = @"ESP会员认证";
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"验证" style:UIBarButtonItemStylePlain target:self action:@selector(navRightItemClicked)];
}


#pragma mark - 导航栏点击
- (void)navRightItemClicked{
    if ([self.authView checkInputs]) {
        [MBProgressHUD showHUDProgress:self.view animated:YES];
        __weak typeof(self) weakSelf = self;
        [MYAFNetworking POST:@"" parameters:self.authView.datas baseUrl:self.authView.currentURL success:^(NSURLSessionDataTask * _Nullable task, id  _Nullable responseObject) {
            [MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
            id data = [responseObject objectForKey:@"data"];
            NSInteger status = [[data safeNumberForKey:@"status"] integerValue];
            if (status == 101) {
                [MBProgressHUD showError:weakSelf.view title:@"用户名错误" code:@"" animated:YES];
                return;
            }
            if (status == 102) {
                [MBProgressHUD showError:weakSelf.view title:@"手机号码错误" code:@"" animated:YES];
                return;
            }
            if (status == 103) {
                [MBProgressHUD showError:weakSelf.view title:@"密码错误" code:@"" animated:YES];
                return;
            }
            if (status != 100) {
                [MBProgressHUD showError:weakSelf.view title:@"验证失败" code:@"" animated:YES];
                return;
            }
            if (weakSelf.authType == 1) {
                GoodsListFiltrateViewController *filtrateVC =[[GoodsListFiltrateViewController alloc] init];
                filtrateVC.gcid = @"23";
                [weakSelf.navigationController pushViewController:filtrateVC animated:YES];
            }else{
                OpenShopIntroVC * vc = [NSClassFromString(@"OpenShopIntroVC") new];
                vc.type = 0;
                [self.navigationController pushViewController:vc animated:YES];
            }
           
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nullable error) {
            [MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
            [MBProgressHUD showError:weakSelf.view title:@"认证失败" code:@"" animated:YES];
        }];
    }
}

- (void)_loadData{
    
}

- (DYESPAuthView *)authView{
    if (!_authView ) {
        _authView = [[DYESPAuthView alloc] init];
    }
    return _authView;
}


@end
